/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nsip.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import nsip.model.ProductPriceInfo;
import nsip.model.messages.AcceptedCustomerRFQsBundle;
import nsip.model.messages.CustomerOrderBundle;
import nsip.model.messages.NewDay;
import nsip.model.messages.SupplierOfferBundle;
import nsip.model.Item;
import nsip.model.DataRecord;
import se.sics.tasim.props.ActiveOrders;
import se.sics.tasim.props.BOMBundle;
import se.sics.tasim.props.BankStatus;
import se.sics.tasim.props.ComponentCatalog;
import se.sics.tasim.props.DeliveryNotice;
import se.sics.tasim.props.FactoryStatus;
import se.sics.tasim.props.MarketReport;
import se.sics.tasim.props.OfferBundle;
import se.sics.tasim.props.PriceReport;
import se.sics.tasim.props.RFQBundle;
import se.sics.tasim.props.SimulationStatus;
import se.sics.tasim.props.StartInfo;

/**
 * 
 * @author nico.rehwaldt
 */
public class Utils {
    public static List<ProductPriceInfo> toPriceInfoList(PriceReport report) {
        List<ProductPriceInfo> prices = new ArrayList(report.size() * 2);
        for (int i = 0; i < report.size(); i++) {
            prices.add(new ProductPriceInfo(
                report.getProductID(i),
                report.getLowestPrice(i),
                report.getHighestPrice(i)
            ));
        }

        return prices;
    }

    /**
     * Converts an array to a list of elements in a null safe manner.
     * If the argument is null, the list returned will be empty.
     * 
     * @param <T>
     * @param array
     * @return
     */
    public static <T> List<T> asList(T[] array) {
        if (array == null) {
            return new ArrayList<T>();
        } else {
            return Arrays.asList(array);
        }
    }
    
    public static final List<Class> AGENT_MESSAGES = Arrays.asList(new Class[] {
            ComponentCatalog.class,
            BOMBundle.class,
            StartInfo.class,
            ActiveOrders.class,
            BankStatus.class,
            MarketReport.class,
            SupplierOfferBundle.class,
            CustomerOrderBundle.class,
            DeliveryNotice.class,
            FactoryStatus.class,
            PriceReport.class,
            SimulationStatus.class,
            OfferBundle.class,
            AcceptedCustomerRFQsBundle.class,
            RFQBundle.class,
            NewDay.class
    });
}
